home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 09 Racing and Sports AI / 04 Adzima / aimath.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-08-19  |  1.8 KB  |  96 lines

  1. #ifndef AI_MATH_H
  2. #define AI_MATH_H
  3.  
  4. class Vector3
  5. {
  6.     public:
  7.         Vector3(){x=0.f;y=0.f;z=0.f;}
  8.  
  9.         void operator=(const Vector3& v);
  10.         Vector3& operator-();
  11.         Vector3& operator-(const Vector3& v);
  12.         Vector3& operator+(const Vector3& v);
  13.         void operator+=(const Vector3& v);
  14.         Vector3& operator*(float scalar);
  15.         float operator^(Vector3& v);    // Do a dot product
  16.  
  17.         void Normalize();
  18.         void Lerp(float percent,Vector3& v1,Vector3& v2);
  19.         void Set(float X,float Y,float Z);
  20.         void Zero(){x=y=z=0.f;}
  21.  
  22.         float Angle(Vector3& Axis);    // Return the angle, based an the axis.
  23.         
  24.     public:
  25.         float x;
  26.         float y;
  27.         float z;
  28. };
  29.  
  30. class Matrix34
  31. {
  32.     public:
  33.         Matrix34(){};
  34.  
  35.         Vector3 XDir;
  36.         Vector3 YDir;
  37.         Vector3 ZDir;
  38.         Vector3 Pos;
  39. };
  40.  
  41. inline float aiDot(const Vector3& A,const Vector3& B){return A.x*B.x+A.z*B.z;}
  42. inline float aiDist(const Vector3& A,const Vector3& B){return (float)sqrt((A.x-B.x)*(A.x-B.x)+(A.z-B.z)*(A.z-B.z));}
  43. inline float aiDist2(const Vector3& A,const Vector3& B){return ((A.x-B.x)*(A.x-B.x)+(A.z-B.z)*(A.z-B.z));}
  44. inline float aiClamp(float fValue,float min,float max){if(fValue<min)fValue=min;if(fValue>max)fValue=max;}
  45. inline float atan2f(float x,float y);
  46.  
  47. void Vector3::operator=(const Vector3& v)
  48. {
  49.     x=v.x;
  50.     y=v.y;
  51.     z=v.z;
  52. }
  53.  
  54. Vector3& Vector3::operator*(float scalar)
  55. {
  56.     Vector3 V;
  57.     V.x=scalar*x;
  58.     V.y=scalar*y;
  59.     V.z=scalar*z;
  60.     return V;
  61. }
  62.  
  63. Vector3& Vector3::operator+(const Vector3& v)
  64. {
  65.     Vector3 V;
  66.     V.x=x+v.x;
  67.     V.y=y+v.y;
  68.     V.z=z+v.z;
  69.     return V;
  70. }
  71.  
  72. Vector3& Vector3::operator-(const Vector3& v)
  73. {
  74.     Vector3 V;
  75.     V.x=x-v.x;
  76.     V.y=y-v.y;
  77.     V.z=z-v.z;
  78.     return V;
  79. }
  80.  
  81. void Vector3::Normalize()
  82. {
  83.     float Mag=sqrt(x*x+y*y+z*z);
  84.     x/=Mag;
  85.     y/=Mag;
  86.     z/=Mag;
  87. }
  88.  
  89. void Vector3::Set(float X,float Y,float Z)
  90. {
  91.     x=X;
  92.     y=Y;
  93.     z=Z;
  94. }
  95.  
  96. #endif